package com.yao.club.controller;

import com.netease.yidun.sdk.core.utils.StringUtils;
import com.yao.club.entity.request.UpdateUserInfoRequest;
import com.yao.club.entity.result.ResponseEntity;
import com.yao.club.entity.result.ResultEntity;
import com.yao.club.entity.vo.UserProfileVO;
import com.yao.club.service.UserService;
import com.yao.club.service.impl.FriendsServiceImpl;
import com.yao.club.token.PassToken;
import com.yao.club.token.UserToken;
import com.yao.club.utils.ResponseUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/app/member")
@Api(value = "用户信息", description = "用户信息接口", tags = "用户信息模块")
public class UserController {
    @Resource
    HttpServletRequest request;
    @Autowired
    UserService userService;

    @UserToken
    @ApiOperation(value = "用户信息", notes = "用户信息", httpMethod = "GET")
    @GetMapping("/getUserInfo")
    public ResponseEntity<UserProfileVO> getUserInfo(){
        String username = (String) request.getAttribute("username");
        return userService.getUserInfo(username);
    }
    @UserToken
    @PostMapping("/updateUserInfo")
    @ApiOperation(value = "修改用户信息", notes = "修改用户信息", httpMethod = "POST")
    public ResponseEntity<Boolean> updateUserInfo(@RequestBody UpdateUserInfoRequest request) {
        String username = (String) this.request.getAttribute("username");
        if (StringUtils.isEmpty(username)) {
            return ResponseUtils.failed("用户未登录");
        }
        return userService.updateUserInfo(username, request);
    }

}
